/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import com.util.FormUtil;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import model.Dosen;

/**
 *
 * @author Adell
 */
public class LoginDosen extends JDialog {

    private JLabel nip;
    private JPasswordField teksnip;
    private JButton tambah;

    public LoginDosen() {
        this.setSize(200, 200);
        FormUtil.centerWindow(this);
        this.setLayout(null);
        this.setVisible(true);
        this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
        this.setTitle(" Form DOSEN ");

        nip = new JLabel(" NIP ");
        nip.setBounds(10, 10, 100, 20);
        nip.setVisible(true);
        this.add(nip);

        teksnip = new JPasswordField();
        teksnip.setBounds(80, 10, 80, 20);
        this.add(teksnip);

        tambah = new JButton("OK");
        tambah.setBounds(50, 50, 100, 20);
        this.add(tambah);

        tambah.addActionListener(new ActionListener() {
            private String[] args;

            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    Connection con = model.Conection.open("jdbc:oracle:thin:@localhost:1521:XE", "hr", "sisil");
                    Statement stat = con.createStatement();
                    Dosen dsn = new Dosen();
                    dsn.setNIP(teksnip.getText());
                    database.UpdateCache.main(args);
                    String cache = "insert into cache(data) values ('" + teksnip.getText() + "')";
                    stat.executeUpdate(cache);
                    FrameUtamaDosen fd = new FrameUtamaDosen(dsn);

                    if (e.getSource() == tambah) {
                        dispose();

                    }
                } catch (SQLException ex) {
                    Logger.getLogger(LoginDosen.class.getName()).log(Level.SEVERE, null, ex);
                }

            }
        });
    }
}
